using System;
using UnityEngine;

public class CameraController : MonoBehaviour
{
    
    [SerializeField] private Transform target;
    [SerializeField] private Vector2 minMaxXY;
    

    private float positionY;
    void Start()
    {
        positionY = transform.position.y;
    }

    void Update()
    {
        
    }

    private void LateUpdate()
    {
        
        Follow();
    }


    private void Follow()
    {
        if (target)
        {
            Vector3 targetPosition = target.position;
            targetPosition.y = positionY;

            targetPosition.x = Mathf.Clamp(targetPosition.x, -minMaxXY.x, minMaxXY.x);
            targetPosition.z = Mathf.Clamp(targetPosition.z, -minMaxXY.y, minMaxXY.y);
            transform.position = targetPosition;
        }
    }
}
